/* Operators.h
Michael Zahniser, 12/12/09

Header file for the Operators class.

To define a new operator and automatically add it to the list of operators, use
the Do<> template.
*/

#ifndef __MZ_OPERATORS_H__
#define __MZ_OPERATORS_H__

#include "_common/Singleton.h"
#include "State.h"

#include <string>
#include <map>



class Operator {
public:
	virtual ~Operator() {}
	virtual void operator()(State &state) const {}
};



class Operators : public Singleton<Operators> {
public:
	void Add(const Operator *op, const std::string &name);
	
	bool Has(const std::string &name) const;
	const Operator &operator[](const std::string &name) const;
	
	
private:
	std::map<std::string, const Operator *> operators;
};



template <const std::string &name>
class Do : public Operator {
public:
	Do() { Operators::GetInstance().Add(this, name); }
	
	virtual void operator()(State &state) const;
};



#endif
